function getSurfaceTerrainHeight(scene, position, opts) {
    opts = opts || {};

    //原始的Cartographic坐标
    var carto = opts.cartesian || Cesium.Cartographic.fromCartesian(position);

    //是否异步求精确高度
    if (opts.asyn) {
        Cesium.when(Cesium.sampleTerrainMostDetailed(scene.terrainProvider, [carto]), function(samples) {
            var clampedCart = samples[0];
            var heightTerrain;
            if (Cesium.defined(clampedCart) && Cesium.defined(clampedCart.height)) {
                heightTerrain = clampedCart.height;
            } else {
                heightTerrain = scene.globe.getHeight(carto);
            }
            if (opts.calback) opts.calback(heightTerrain, carto);
        });
    } else {
        var heightTerrain = scene.globe.getHeight(carto);
        if (Cesium.defined(heightTerrain) && heightTerrain > -1000) {
            if (opts.calback) opts.calback(heightTerrain, carto);
            return heightTerrain;
        }
    }
    return 0; //表示取值失败
}


//获取坐标的贴地(或贴模型)高度
function getSurfaceHeight(scene, position, opts) {
    if (scene instanceof Cesium.Viewer) //兼容传入viewer
        scene = scene.scene;
    opts = opts || {};

    //求贴地形高度
    return getSurfaceTerrainHeight(scene, position, opts);

}

//求Rectangle范围内 按count等比插值的granularity值
function getGranularity(positions, count) {
    var recta = Cesium.Rectangle.fromCartesianArray(positions);
    var granularity = Math.max(recta.height, recta.width);
    granularity /= Cesium.defaultValue(count, 10); //默认分割10次
    return granularity;
}

//路线进行贴地(或贴模型)插值, splitNum为次数
function interPolyline(opts) {
    var positions = opts.positions;
    var scene = opts.scene;

    var granularity = getGranularity(positions, opts.splitNum || 100);
    if (granularity <= 0) granularity = null;

    var flatPositions = Cesium.PolylinePipeline.generateArc({
        positions: positions,
        height: opts.height, //未传入时，内部默认为0
        minDistance: opts.minDistance, //插值间隔(米)，优先级高于granularity
        granularity: granularity //splitNum分割的个数
    });

    var arrPoint = [];
    var arrHB=[];
    var arrLen=[];
    var all_distance = 0;
    for (var i = 0; i < flatPositions.length; i += 3) {
        var position = Cesium.Cartesian3.unpack(flatPositions, i);
        if (scene && Cesium.defaultValue(opts.surfaceHeight, true)) {
            var height = getSurfaceHeight(scene, position, opts);
            var car = Cesium.Cartographic.fromCartesian(position);
            arrPoint.push(car);
            arrHB.push(height);
            //长度
            if (i >= 3) {
                var S=Cesium.Cartesian3.unpack(flatPositions, 0);
                all_distance = Cesium.Cartesian3.distance(position, S);
            }
            arrLen.push(Number(all_distance.toFixed(1)));
            //position = Cesium.Cartesian3.fromRadians(car.longitude, car.latitude, height);
        }
    }
    return {arrHB:arrHB,arrPoint:arrPoint,arrLen:arrLen};
}